package com.cz.basetool.ui_work.util.system;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;

import com.cz.basetool.ui_work.util.log.AndroidConsoleLogPrinter;


/**
 * Created by 陈章 on 2017/12/26.
 */

public class VersionUtil {

    /**
     * 返回当前程序版本名
     */
    public static String getAppVersionName(Context context) {
        String versionName = "";
        try {
            // ---get the package info---
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionName;
            if (versionName == null || versionName.length() <= 0) {
                return "";
            }
        } catch (Exception e) {
            AndroidConsoleLogPrinter.e("VersionInfo", e.getMessage());
        }
        return versionName;
    }

    /**
     * 设备名称
     * @return
     */
    public static String getDeviceName(){
        return android.os.Build.MANUFACTURER;
    }

    /**
     * POS设备的序列号
     * @param context
     * @return
     */
    public static String getAndroidID(Context context){
        String m_szAndroidID = Settings.Secure.getString(context.getContentResolver(),
                Settings.Secure.ANDROID_ID);
        return m_szAndroidID;
    }

    /**
     * 获取IMEI号方法
     * @param context
     * @return
     */
    @SuppressLint("MissingPermission")
    public static String getDeviceId(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return telephonyManager.getDeviceId();
    }

}
